package masterjava.common.client.gxt.base.tree;

import com.extjs.gxt.ui.client.data.BaseTreeModel;
import masterjava.common.client.gxt.base.model.GenericModel;
import masterjava.common.client.gxt.base.model.GenericModelType;
import masterjava.common.shared.HasKey;
import org.jetbrains.annotations.Nullable;

/**
 * User: gkislin
 * Date: 8/1/11
 */
public class GenericTreeModel extends BaseTreeModel implements HasKey {
    public static final String TYPE = "type";
    public static final String ID = "id";

    private final HasKey data;
    private final Long id;
    private final GenericModelType type;

    public GenericTreeModel(HasKey name, Long id) {
        this(name, id, null);
    }

    public GenericTreeModel(HasKey nameData, Long id, @Nullable GenericModelType modelType) {
        this.data = nameData;
        this.type = modelType;
        this.id = id;
        set(GenericModel.KEY, nameData.getKey());
        set(TYPE, modelType.name());
        set(ID, String.valueOf(id));
    }

    public HasKey getData() {
        return data;
    }

    @Override
    public String getKey() {
        return data.getKey();
    }

    public GenericModelType getType() {
        return type;
    }

    public Long getId() {
        return id;
    }
}
